package app;

import mission.Mission;

import org.apache.mina.core.service.IoHandler;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

import core.MissionSaver;

public class ServerHandler implements IoHandler {

	@Override
	public void sessionCreated(IoSession session) throws Exception 
	{

	}

	@Override
	public void sessionOpened(IoSession session) throws Exception 
	{

	}

	@Override
	public void sessionClosed(IoSession session) throws Exception 
	{

	}

	@Override
	public void sessionIdle(IoSession session, IdleStatus status)
			throws Exception 
	{

	}

	@Override
	public void exceptionCaught(IoSession session, Throwable cause)
			throws Exception 
	{

	}

	/**
	 * 收到客户端的消息
	 * 然后全部保存在缓存器中
	 * @param message {@link mission.Mission}
	 * @see org.apache.mina.core.service.IoHandler#messageReceived(org.apache.mina.core.session.IoSession, java.lang.Object)
	 */
	@Override
	public void messageReceived(IoSession session, Object message)
			throws Exception 
	{
		Mission mon = (Mission) message;
		MissionSaver.getInstance().addMission(mon);
	}

	@Override
	public void messageSent(IoSession session, Object message) throws Exception 
	{
		
	}

}
